package cn.hznc.constant;

import cn.hutool.core.util.ObjectUtil;
import cn.hznc.domain.entity.OrderEntity;

import java.math.BigDecimal;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author：Administrator
 * @Date：2023/7/12 11:33
 */
public enum SortOrderEnum implements SortOrder{
    TaskId{
        @Override
        public List<OrderEntity> sortByCondition(List<OrderEntity> orderEntities, Integer sortType){
            if(sortType == 0){
                //正序
                return orderEntities
                        .stream()
                        .sorted(Comparator.comparing(OrderEntity::getTaskId , Comparator.comparing(Integer::valueOf)))
                        .collect(Collectors.toList());
            }
            //倒序
            return orderEntities
                    .stream()
                    .sorted(Comparator.comparing(OrderEntity::getTaskId , Comparator.comparing(Integer::valueOf)).reversed())
                    .collect(Collectors.toList());
        }
    },

    ProductionNum{
        @Override
        public List<OrderEntity> sortByCondition(List<OrderEntity> orderEntities , Integer sortType){
            if(sortType == 0){
                //正序
                return orderEntities
                        .stream()
                        .sorted(Comparator.comparing(OrderEntity::getProductionNum , Comparator.nullsFirst(String::compareTo)))
                        .collect(Collectors.toList());
            }
            //倒序
            return orderEntities
                    .stream()
                    .sorted(Comparator.comparing(OrderEntity::getProductionNum , Comparator.nullsLast(String::compareTo)))
                    .collect(Collectors.toList());
        }
    },

    Priority{
        @Override
        public List<OrderEntity> sortByCondition(List<OrderEntity> orderEntities, Integer sortType){
            if(sortType == 0){
                //正序
                return orderEntities
                        .stream()
                        .sorted(Comparator.comparing(OrderEntity::getPriority , Comparator.nullsFirst(String::compareTo)))
                        .collect(Collectors.toList());
            }
            //倒序
            return orderEntities
                    .stream()
                    .sorted(Comparator.comparing(OrderEntity::getPriority , Comparator.nullsLast(String::compareTo)))
                    .collect(Collectors.toList());
        }
    },

    AbutmentPriority{
        @Override
        public List<OrderEntity> sortByCondition(List<OrderEntity> orderEntities, Integer sortType){
            if(sortType == 0){
                //正序
                return orderEntities
                        .stream()
                        .sorted(Comparator.comparing(OrderEntity::getSortPriority , Comparator.nullsFirst(Integer::compareTo)))
                        .collect(Collectors.toList());
            }
            //倒序
            return orderEntities
                    .stream()
                    .sorted(Comparator.comparing(OrderEntity::getSortPriority , Comparator.nullsLast(Integer::compareTo)))
                    .collect(Collectors.toList());
        }
    },

    MaterialNo{
        @Override
        public List<OrderEntity> sortByCondition(List<OrderEntity> orderEntities, Integer sortType){
            if(sortType == 0){
                //正序
                return orderEntities
                        .stream()
                        .sorted(Comparator.comparing(OrderEntity::getMaterialNo , Comparator.nullsFirst(String::compareTo)))
                        .collect(Collectors.toList());
            }
            //倒序
            return orderEntities
                    .stream()
                    .sorted(Comparator.comparing(OrderEntity::getMaterialNo , Comparator.nullsLast(String::compareTo)))
                    .collect(Collectors.toList());
        }
    },

    Heavy{
        @Override
        public List<OrderEntity> sortByCondition(List<OrderEntity> orderEntities, Integer sortType){
            if(sortType == 0){
                //正序
                return orderEntities
                        .stream()
                        .sorted(Comparator.comparing(OrderEntity::getHeavy , Comparator.nullsFirst(BigDecimal::compareTo)))
                        .collect(Collectors.toList());
            }
            //倒序
            return orderEntities
                    .stream()
                    .sorted(Comparator.comparing(OrderEntity::getHeavy , Comparator.nullsLast(BigDecimal::compareTo)))
                    .collect(Collectors.toList());
        }
    },

    PlanNumber{
        @Override
        public List<OrderEntity> sortByCondition(List<OrderEntity> orderEntities, Integer sortType){
            if(sortType == 0){
                //正序
                return orderEntities
                        .stream()
                        .sorted(Comparator.comparing(OrderEntity::getPlanNumber))
                        .collect(Collectors.toList());
            }
            //倒序
            return orderEntities
                    .stream()
                    .sorted(Comparator.comparing(OrderEntity::getPlanNumber).reversed())
                    .collect(Collectors.toList());
        }
    },

    RealNumber{
        @Override
        public List<OrderEntity> sortByCondition(List<OrderEntity> orderEntities, Integer sortType){
            if(sortType == 0){
                //正序
                return orderEntities
                        .stream()
                        .sorted(Comparator.comparing(OrderEntity::getRealNumber))
                        .collect(Collectors.toList());
            }
            //倒序
            return orderEntities
                    .stream()
                    .sorted(Comparator.comparing(OrderEntity::getRealNumber).reversed())
                    .collect(Collectors.toList());
        }
    },

    FinishTime{
        @Override
        public List<OrderEntity> sortByCondition(List<OrderEntity> orderEntities, Integer sortType){
            if(sortType == 0){
                //正序
                return orderEntities
                        .stream()
                        .sorted(Comparator.comparing(OrderEntity::getFinishTime))
                        .collect(Collectors.toList());
            }
            //倒序
            return orderEntities
                    .stream()
                    .sorted(Comparator.comparing(OrderEntity::getFinishTime).reversed())
                    .collect(Collectors.toList());
        }
    },


    ReleaseTime{
        @Override
        public List<OrderEntity> sortByCondition(List<OrderEntity> orderEntities, Integer sortType){
            if(sortType == 0){
                //正序
                return orderEntities
                        .stream()
                        .filter(orderEntity -> ObjectUtil.isNotNull(orderEntity.getReleaseTime()))
                        .sorted(Comparator.comparing(OrderEntity::getReleaseTime))
                        .collect(Collectors.toList());
            }
            //倒序
            return orderEntities
                    .stream()
                    .filter(orderEntity -> ObjectUtil.isNotNull(orderEntity.getReleaseTime()))
                    .sorted(Comparator.comparing(OrderEntity::getReleaseTime).reversed())
                    .collect(Collectors.toList());
        }
    },

    InboundTime{
        @Override
        public List<OrderEntity> sortByCondition(List<OrderEntity> orderEntities, Integer sortType){
            if(sortType == 0){
                //正序
                return orderEntities
                        .stream()
                        .sorted(Comparator.comparing(OrderEntity::getInboundTime , Comparator.nullsLast(Long::compareTo)))
                        .collect(Collectors.toList());
            }
            //倒序
            return orderEntities
                    .stream()
                    .sorted(Comparator.comparing(OrderEntity::getInboundTime , Comparator.nullsFirst(Long::compareTo)).reversed())
                    .collect(Collectors.toList());
        }
    },

    StandTime{
        @Override
        public List<OrderEntity> sortByCondition(List<OrderEntity> orderEntities, Integer sortType){
            if(sortType == 0){
                //正序
                return orderEntities
                        .stream()
                        .sorted(Comparator.comparing(OrderEntity::getStandTime , Comparator.nullsLast(Long::compareTo)))
                        .collect(Collectors.toList());
            }
            //倒序
            return orderEntities
                    .stream()
                    .sorted(Comparator.comparing(OrderEntity::getStandTime , Comparator.nullsFirst(Long::compareTo)).reversed())
                    .collect(Collectors.toList());
        }
    },

    CycleTime{
        @Override
        public List<OrderEntity> sortByCondition(List<OrderEntity> orderEntities, Integer sortType){
            if(sortType == 0){
                //正序
                return orderEntities
                        .stream()
                        .sorted(Comparator.comparing(OrderEntity::getCycleTime , Comparator.nullsLast(Long::compareTo)))
                        .collect(Collectors.toList());
            }
            //倒序
            return orderEntities
                    .stream()
                    .sorted(Comparator.comparing(OrderEntity::getCycleTime , Comparator.nullsFirst(Long::compareTo)).reversed())
                    .collect(Collectors.toList());
        }
    },

    InCraftName{
        @Override
        public List<OrderEntity> sortByCondition(List<OrderEntity> orderEntities, Integer sortType){
            if(sortType == 0){
                //正序
                return orderEntities
                        .stream()
                        .sorted(Comparator.comparing(OrderEntity::getInCraftName , Comparator.nullsLast(String::compareTo)))
                        .collect(Collectors.toList());
            }
            //倒序
            return orderEntities
                    .stream()
                    .sorted(Comparator.comparing(OrderEntity::getInCraftName , Comparator.nullsFirst(String::compareTo)).reversed())
                    .collect(Collectors.toList());
        }
    },

    SortPriority{
        @Override
        public List<OrderEntity> sortByCondition(List<OrderEntity> orderEntities, Integer sortType){
            if(sortType == 0){
                //正序
                return orderEntities
                        .stream()
                        .sorted(Comparator.comparing(OrderEntity::getSortPriority , Comparator.nullsLast(Integer::compareTo)))
                        .collect(Collectors.toList());
            }
            //倒序
            return orderEntities
                    .stream()
                    .sorted(Comparator.comparing(OrderEntity::getSortPriority , Comparator.nullsFirst(Integer::compareTo)).reversed())
                    .collect(Collectors.toList());
        }
    },


}
